package logger

import (
	"github.com/fatih/color"
	"github.com/sirupsen/logrus"
	"os"
)

type prefixFormatter struct {
	Prefix []byte
	logrus.TextFormatter
}

func (f *prefixFormatter) Format(entry *logrus.Entry) ([]byte, error) {
	bs, err := f.TextFormatter.Format(entry)
	if err != nil {
		return nil, err
	}
	return append(f.Prefix, bs...), nil
}

func SetLogger() {
	logrus.SetFormatter(&prefixFormatter{
		Prefix:        []byte(color.HiGreenString("[tfwrapper] ")),
		TextFormatter: logrus.TextFormatter{DisableTimestamp: true, ForceColors: true},
	})
	logrus.SetOutput(os.Stderr)
}
